package org.jeecg.modules.flowable.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.flowable.entity.FlowCategory;
import org.jeecg.modules.flowable.service.FlowCategoryService;
import org.jeecg.modules.flowable.vo.FlowCategoryVO;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "流程分类")
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/flow/category")
public class FlowCategoryController {

    final FlowCategoryService flowCategoryService;

    @AutoLog(value = "流程分类管理-通过id查询")
    @ApiOperation(value = "根据id查询流程分类", notes = "根据id查询流程分类")
    @GetMapping("/{id}")
    public Result<FlowCategory> getById(@PathVariable Long id) {
        return Result.OK(this.flowCategoryService.getById(id));
    }

    @AutoLog(value = "流程分类管理-添加")
    @ApiOperation(value = "添加流程分类", notes = "添加流程分类")
    @PostMapping
    public Result<Void> add(@RequestBody FlowCategory category) {
        this.flowCategoryService.save(category);
        return Result.OK();
    }

    @AutoLog(value = "流程分类管理-修改")
    @ApiOperation(value = "修改流程分类", notes = "修改流程分类")
    @PutMapping
    public Result<Void> edit(@RequestBody FlowCategory category) {
        this.flowCategoryService.updateById(category);
        return Result.OK();
    }

    @AutoLog(value = "流程分类管理-删除")
    @ApiOperation(value = "删除流程分类", notes = "删除流程分类")
    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        this.flowCategoryService.removeById(id);
        return Result.OK();
    }

    @AutoLog(value = "流程分类管理-列表查询")
    @ApiOperation(value = "列表查询流程分类", notes = "列表查询流程分类")
    @GetMapping("/list")
    public Result<List<FlowCategoryVO>> list() {
        return Result.OK(this.flowCategoryService.queryList());
    }

}
